<?php
require "Db\DbHelper.php";
require "Tools\WebResult.php";

use Tools\WebResult;
use Db\DbHelper;

$book_id = $_REQUEST['book_id'];
$logged_user = $_SESSION['user'];

// 未登录
if (empty($logged_user)) {
    WebResult::JsonFail('please_login_first！');
}

if (empty($book_id)) {
    WebResult::JsonEmpty();
}

// 添加当前图书到当前登录用户的购物车
$db = DBHelper::createPDO();
$stmt = $db->prepare('delete from cart where book_id = ? and user_id = ?');
$stmt->bindValue(1, $book_id);
$stmt->bindValue(2, $logged_user['id']);

$stmt->execute();

WebResult::JsonSuccess();
